package com.webchat.ugc.repository.dao.mall;

import com.webchat.ugc.repository.entity.mall.MallProductOrderEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;


@Repository
public interface IMallProductOrderDAO extends JpaRepository<MallProductOrderEntity, Long>,
                                              JpaSpecificationExecutor<MallProductOrderEntity> {


    MallProductOrderEntity findAllByOrderNo(String orderNo);


    @Transactional
    @Modifying
    @Query(value = "update MallProductOrderEntity order set order.paymentStatus = :paymentStatus where order.orderNo = :orderNo")
    int updateOrderPaymentStatus(String orderNo, Integer paymentStatus);

    @Transactional
    @Modifying
    @Query(value = "update MallProductOrderEntity order " +
            "set order.paymentStatus = :paymentStatus, order.logisticsStatus = :logisticsStatus " +
            "where order.orderNo = :orderNo")
    int updateOrderPaymentAndLogisticsStatusStatus(String orderNo, Integer paymentStatus, Integer logisticsStatus);


    @Transactional
    @Modifying
    @Query(value = "update MallProductOrderEntity o " +
                   "set o.transId = :transId, o.paymentOrderId = :paymentOrderId, o.paymentStatus = :paymentStatus " +
                   "where o.orderNo = :orderNo")
    int updateOrderPaymentInfo(String orderNo, String transId, String paymentOrderId, Integer paymentStatus);
}
